package LeetCode精选TOP面试题;

import java.util.Arrays;

public class p58最后一个单词的长度 {
    public int lengthOfLastWord(String s) {
        String[] strings = s.trim().split(" ");
        return strings[strings.length-1].length();
    }

    public static void main(String[] args) {
        String s="   fly me   to   the moon  ";
        String[] strings = s.split(" ");
        System.out.println(strings.length);
        System.out.println(Arrays.toString(strings));
        System.out.println(strings[0]);
        System.out.println(strings[3]);


        String s2="  a b c ";
        String[] strings2 = s2.split(" ");//最后的空格会被分割掉，而字符串前面的不会
        System.out.println(strings2.length);
        System.out.println(Arrays.toString(strings2));

        String s23="  a b c ";
        String[] strings23 = s23.trim().split(" ");//最后的空格会被分割掉，而字符串前面的不会
        System.out.println(strings23.length);
        System.out.println(Arrays.toString(strings23));
    }
}
